//index.js
//获取应用实例
const app = getApp()
const Api = require("../../utils/api.js").API
// const Store = require("../../utils/store.js").store
const codeZ = require("../../utils/util.js")
Page({
    data: { 
        
        goods: {}, 
        list:[],
        showKe:false,
        showXin:false,
        showGZ:false,
        shopkeeperCkNo:'',
    },
    onLoad() {


        let that = this;
        var bean;
        const eventChannel = this.getOpenerEventChannel();
        eventChannel.on('acceptDataFromOpenerPage', function(data) {

            bean = data.type;

            that.setData({
                goods: data.data,
                shopkeeperCkNo:data.shopkeeperCkNo
                
            })

        })


        console.log(this.data.value);

    },
   
    onShow: function() {
        let that = this;
       
        Api.cheakGroupApi().then(res => {
            
            if (res.code == 0) {
                    var arr =res.data.groupInfo;
                    console.log(arr);
                    if(arr.length == 0){         
                            that.setData({
                                list: [],   
                                
                            })
                            
                        
                    }else{
                        // arr.forEach(ite=>{
                        //     if(ite.recipientInfo != null){
                        //         ite.recipientInfo.forEach(item=>{
                        //             item.skuNum = 1;
                        //         })
                                
                        //     }
                        // })
                        that.setData({
                            list: arr,
                            
                            
                        })
                    }
               
                 
                 
               
            }else{
                that.setData({
                    list: [],
                   
                    
                })
            }
        })
        
      
 


    },
    addAddress(){
        if(this.data.list.length == 0){
            wx.navigateTo({
                url:'../adressEdit/index?fenzhu=false'
            })
        }else{
            let a = this.data.list[0].recipientInfo[0];
            let b = this.data.list[0].ckGroupNo;
              let c = this.data.list[0].ckGroupName;
            
            // data-item="{{item}}" data-lxName="{{ite.ckGroupName}}"  data-lxNo="{{ite.ckGroupNo}}"
            let dic = JSON.stringify({
                'item':a,
                'lxNo':b,
                'lxName':c,
                'cust':true
            })
            
           
            wx.navigateTo({
                url:'../adressEdit/index?item='+dic+'&fenzhu=false'
            })
        }
      
        
    },
  
  fuzhi:function(e){
    
      
        wx.setClipboardData({  data:'好麦优选',})
        
    },
    
    fuzhi2(){
        let a = this.data.goods.phoneNo;
        wx.makePhoneCall({
           phoneNumber:a,
           success:function(){
            
           },
           fail:function(){
             
             // console.log('拨打失败')
           }
        })
    },
    addHj1() {
        wx.makePhoneCall({
            phoneNumber: this.data.goods.phoneNo,
            success: function() {

            },
            fail: function() {

                // console.log('拨打失败')
            }
        })
    },
    wanc(){
        this.setData({
            showXin:false,
             showGZ:true,
   
        });
        
        
        
        // 
       
       
    },
    onCloseo(){
        this.setData({
            
           
             showGZ:false,
            
        });
        wx.navigateBack();
    },
    
    onClose() {
        this.setData({
            
            showKe:false,
             showXin:false,
            
            
        });
    },
    
     
        
         
    
    calld(){
        this.setData({
            showKe:true,
        });
        
    },
    callm(){
        let that = this;
       let openId =   wx.getStorageSync('openId');
       let listAddr =this.data.list[0].recipientInfo[0];
        let data = {
	"addr": listAddr.addr,
	"area": listAddr.area,
	"city": listAddr.city,
	"contactName": listAddr.contactName,
	"contactTel": listAddr.contactPhone,
	"distributionTime": "",
	"openId": openId,
	"province": listAddr.province,
	"remark": "",
	"shelveNo": this.data.goods.shelveNo,
	"shopkeeperCkNo": this.data.shopkeeperCkNo,
	"skuNo": this.data.goods.skuNo,
	"skuNum": 1
}
        
        
        Api.ckOrderCreateApi(data).then(res=>{
           
            that.setData({
                showXin:true,
            });
        })
        
        
       
    }
 

});
